
package cn.org.seventh.web.tag;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @author <a href="mailto:ji.li@symbio-group.com">Andy</a>
 * @since Dec 3, 2007 10:54:55 AM
 */
public class FCKEditorConfigurations extends HashMap {

    /**
     * 
     */
    private static final long serialVersionUID = 6881519952347327233L;

    /**
     * Initialize the configuration collection
     */
    public FCKEditorConfigurations() {
        super();
    }

    /**
     * Generate the url parameter sequence used to pass this configuration to
     * the editor.
     * 
     * @return html endocode sequence of configuration parameters
     */
    public String getUrlParams() {
        StringBuffer osParams = new StringBuffer();
        for (Iterator i = this.entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();
            if (entry.getValue() != null)
                osParams.append("&" + encodeConfig(entry.getKey().toString())
                    + "=" + encodeConfig(entry.getValue().toString()));
        }
        return osParams.toString();
    }

    private String encodeConfig(String txt) {
        txt = txt.replaceAll("&", "%26");
        txt = txt.replaceAll("=", "%3D");
        txt = txt.replaceAll("\"", "%22");
        return txt;
    }
}
